home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / rayshade / libray / libtext / checker.c < prev    next >
C/C++ Source or Header  |  1994-08-01  |  1KB  |  60 lines

  1. /*
  2.  * checker.c
  3.  *
  4.  * Copyright (C) 1989, 1991, Craig E. Kolb
  5.  * All rights reserved.
  6.  *
  7.  * This software may be freely copied, modified, and redistributed
  8.  * provided that this copyright notice is preserved on all copies.
  9.  *
  10.  * You may not distribute this software, in whole or in part, as part of
  11.  * any commercial product without the express consent of the authors.
  12.  *
  13.  * There is no warranty or other guarantee of fitness of this software
  14.  * for any purpose.  It is provided solely "as is".
  15.  *
  16.  * $Id: checker.c,v 4.0 91/07/17 14:41:48 kolb Exp Locker: kolb $
  17.  *
  18.  * $Log:    checker.c,v $
  19.  * Revision 4.0  91/07/17  14:41:48  kolb
  20.  * Initial version.
  21.  * 
  22.  */
  23. #include "texture.h"
  24. #include "checker.h"
  25.  
  26. /*
  27.  * Create and return a reference to a "checker" texture.
  28.  */
  29. Checker *
  30. CheckerCreate(surf)
  31. Surface *surf;
  32. {
  33.     Checker *checker;
  34.     checker = (Checker *)Malloc(sizeof(checker));
  35.     checker->surf = surf;
  36.     return checker;
  37. }
  38.  
  39. /*
  40.  * Apply a "checker" texture.
  41.  */
  42. void
  43. CheckerApply(checker, prim, ray, pos, norm, gnorm, surf)
  44. Checker *checker;
  45. Geom *prim;
  46. Ray *ray;
  47. Vector *pos, *norm, *gnorm;
  48. Surface *surf;
  49. {
  50.     int xp, yp, zp;
  51.  
  52.     xp = pos->x > 0. ? pos->x : 1. - pos->x;
  53.     yp = pos->y > 0. ? pos->y : 1. - pos->y;
  54.     zp = pos->z > 0. ? pos->z : 1. - pos->z;
  55.  
  56.     if ((xp + yp + zp) % 2)
  57.         *surf = *checker->surf;
  58.     /* else surface stays the same. */
  59. }
  60.